﻿using System;
using System.Windows;

namespace MS.Common.Theme
{
    public class ThemeHelper
    {
        public DataTemplate GetDataTemplate(string keyname)
        {
            return getDataTemplate(keyname);

            DataTemplate getDataTemplate(params string[] keys)
            {
                foreach (string key in keys)
                {
                    if (TryGetDataTemplate(key, out DataTemplate color))
                    {
                        return color;
                    }
                }
                throw new InvalidOperationException($"Could not locate required resource with key(s) '{string.Join(", ", keys)}'");
            }
            bool TryGetDataTemplate(string key, out DataTemplate template)
            {
                if (Application.Current.Resources[key] is DataTemplate temp)
                {
                    template = temp;
                    return true;
                }

                template = null;
                return false;
            }
        }
    }
}
